package com.taijihuabao.modules.controller;

import com.alibaba.excel.EasyExcel;
import com.taijihuabao.common.excel.ExpenseExcelLister;
import com.taijihuabao.common.jsonresult.JsonResult;
import com.taijihuabao.modules.entity.ReimbursementEntity;
import com.taijihuabao.modules.model.reimbursement.ReimbursementExportDTO;
import com.taijihuabao.modules.model.reimbursement.ReimbursementImportDTO;
import com.taijihuabao.modules.service.ReimbursementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @title: ReimbursementController
 * @Author luoxianan
 * @Date: 2022/1/12 10:19
 * @Version 1.0
 */
@Api(tags = "报销单导出管理")
@RestController
@RequestMapping("/api/v1/Reimbursement")
public class ReimbursementController {
    @Autowired
    private ReimbursementService reimbursementService;
    @ApiOperation("导入报销数据")
    @PostMapping("/importExcel")
    public JsonResult importExcel(ReimbursementImportDTO reimbursementImportDTO) throws IOException {
        MultipartFile file = reimbursementImportDTO.getFile();
        String sheetName = reimbursementImportDTO.getSheetName();
        Integer headRowNumber = reimbursementImportDTO.getHeadRowNumber();
        EasyExcel.read(file.getInputStream(), ReimbursementEntity.class,new ExpenseExcelLister(reimbursementService)).sheet(sheetName).headRowNumber(headRowNumber).doRead();
        return JsonResult.success();
    }

    @ApiOperation("导出全部报销数据")
    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response, ReimbursementExportDTO reimbursementExportDTO) throws IOException{
        reimbursementService.selectAll(response,reimbursementExportDTO);
    }

    @ApiOperation("导出月份数据")
    @GetMapping("/exportMonthExcel")
    public void exportMonthExcel(HttpServletResponse response, ReimbursementExportDTO reimbursementExportDTO) throws IOException{
        reimbursementService.selectByMonth(response,reimbursementExportDTO);
    }

    @ApiOperation("导出周数据")
    @GetMapping("/exportWeekExcel")
    public void exportWeekExcel(HttpServletResponse response, ReimbursementExportDTO reimbursementExportDTO) throws IOException{
        reimbursementService.selectByWeek(response,reimbursementExportDTO);
    }
}
